<?php

namespace app\common\model\Business;

use app\common\model\Order\Order as OrderOrder;
use app\common\model\Subject\Order;
use think\Model;

class Commission extends Model
{
    // 表名
    protected $name = 'business_commission';
    // 忽略数据表不存在的字段
    protected $field = true;
    // 设置返回的结果类型
    protected $resultSetType = 'collection';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    //禁止写入时间字段
    protected $updateTime = false;
    // 软删除的字段
    protected $deleteTime = 'deletetime';
    // 追加属性
    protected $append = [
        'order',
        'business'
    ];
    public function getOrderAttr($value,$data)
    {
        if($data['type']=='subject')
        {
            return $this->hasOne(Order::class,'id','orderid')->find();
        }else if($data['type']=='product')
        {
            return $this->hasOne(OrderOrder::class,'id','orderid')->find();
        }
    }
    public function business()
    {
        return $this->belongsTo(Business::class,'parentid','id',[],'left')->setEagerlyType(0);
    }
}
